package bus.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import bus.dao.TicketDao;
import bus.dao.UserDao;
import bus.moudle.Admin;
import bus.moudle.User;
import bus.util.DButil;

class trip2
{
	public void qie(String li)
	{
	  Print.jf.setText(li);
	}
}
public class Print extends JPanel implements ActionListener {
		JLabel l1;
		JButton b1, b2;
		public static JTextField jf;
		public String username;
		Print(String username){
			this.username=username;
			l1=new JLabel("Enter Ticket Number:");
			l1.setBounds(50, 200, 200, 20);
			l1.setFont(new Font("Arial", Font.BOLD, 15));
			
			jf=new JTextField();
			jf.setBounds(250, 200, 250, 30);
			jf.setFont(new java.awt.Font("Dialog",1, 15));
			jf.setBackground(Color.yellow);
			
			
			b1=new JButton("Print");
			b1.setBounds(350, 350, 100, 30);
			b1.setFont(new Font("Arial", Font.BOLD, 20));
			
			b2=new JButton("search");
			b2.setBounds(550, 200, 100, 30);
			b2.setFont(new Font("Arial", Font.BOLD, 20));
			
			setLayout(null);
			add(l1);add(jf);add(b1);add(b2);
			
			b1.addActionListener(this);
			b2.addActionListener(this);
		}
		@Override
		public void actionPerformed(ActionEvent e) {
			try {
			//	System.out.println(e.getActionCommand().equals("Print"));
			if(e.getActionCommand().equals("Print")) {
				DButil dbUtil=new DButil();
				Connection con=dbUtil.getCon();
				String str=jf.getText();
				TicketDao td=new TicketDao();
				Admin ticket=new Admin();
				ticket.setTickno(str);	
				ResultSet rs=td.ticketSearch(con, ticket);
				//System.out.println(rs.next());
				if(rs.next()) {
				//	System.out.println();
					new MainFrame(rs.getString(1)).setVisible(true);;	
					
				}
				else {
					JOptionPane.showMessageDialog(this, "Please check your ticketnumber");
				}
				
			}
			else {
			  
			  Ticket_Info l=new Ticket_Info(2, username);
			  //System.out.println(l.search());
			   jf.setText(l.search());
			}
			
			}
		    
		  catch(Exception e1) {
			  e1.printStackTrace();
				System.out.print(e1);
			}
		}
		
	}
